namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class IndicatorBIAS : BaseIndicator
    {
        private string closeSMA = ("BIAS.CloseMA." + Common.GetGuid());
        private LineShape tlsBias;

        public IndicatorBIAS()
        {
            base.IndType = IndicatorType.BIAS;
            base.IndName = "BIAS";
            base.IndDesc = "乖离率";
            base.IndPeriod.Add(new IndicatorPeriod(0, "L", 6.0));
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "BIAS" };
        }

        public override bool Contains(object obj)
        {
            return (obj == this.tlsBias);
        }

        public override double[] Get(int r)
        {
            double curValue = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            double num2 = Common.CalcuteMovingAvg(r, (int) base.IndPeriod[0].ParamValue, this.CloseSMA, base.SourceDic["Close"], curValue, base.Crab.DataSource);
            if (num2 != 0.0)
            {
                return new double[] { (((curValue - num2) / num2) * 100.0), num2 };
            }
            return new double[2];
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.tlsBias };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsBias);
            base.Crab.DataSource.Columns.Remove(this.CloseSMA);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double[] numArray = this.Get(r);
                        base.Crab.SetValue(this.TlsBias.Name, numArray[0], r);
                        base.Crab.SetValue(this.CloseSMA, numArray[1], r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            base.SourceDic["Close"] = source[0];
            base.IndPeriod[0].ParamValue = periods[0];
            base.Crab.DataSource.Columns.Add(this.CloseSMA);
            this.TlsBias = base.Crab.AddLine(fields[0], panelID);
        }

        public string CloseSMA
        {
            get
            {
                return this.closeSMA;
            }
            set
            {
                this.closeSMA = value;
            }
        }

        public LineShape TlsBias
        {
            get
            {
                return this.tlsBias;
            }
            set
            {
                this.tlsBias = value;
            }
        }
    }
}

